package org.sport.logic;

import org.sport.dbInterface.ActLinkUserOperation;
import org.sport.dbInterface.ActivityOperation;
import org.sport.dbInterface.DiscussOperation;
import org.sport.dbInterface.ParActOperation;
import org.sport.init.SportClientSymbol;
import org.sport.init.SportServerSymbol;
import org.sport.model.entityModel.*;
import org.sport.model.jsonModel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zehong
 *
 * 关于管理活动的所有操作
 * 三种展示：全部，我参与的，我发布的
 * 具体操作有：查看全部活动，单个活动，活动评论，进行评论
 */

@Service
public class Logic_SportActivity {

    @Autowired
    LogicUtils logicUtils;

    @Autowired
    ActivityOperation actOperation;

    @Autowired
    DiscussOperation discussOperation;

    @Autowired
    ParActOperation parActOperation;

    @Autowired
    ActLinkUserOperation actLinkUserOperation;



    //创建活动
    public Json_3_createActivity createActivity(Json_3_createActivity json_3_createActivity){
        System.out.println("进入Logic-createActivity");

        //找到该用户
        UsertableEntity userForUse=logicUtils.findUser(json_3_createActivity.getPhoneNumber());

        //新建活动实例
        ActivitytableEntity activity=new ActivitytableEntity();
        activity.setCreateTime(new Timestamp(System.currentTimeMillis()));
        activity.setBeginTime(Timestamp.valueOf(json_3_createActivity.getBeginTime()));
        activity.setEndTime(Timestamp.valueOf(json_3_createActivity.getEndTime()));
        activity.setTheam(json_3_createActivity.getTheam());
        activity.setTotPeo(1+"");
        activity.setLocation(json_3_createActivity.getLocation());
        activity.setStatus(SportServerSymbol.activitytable.STATUS_ACTIVE);
        activity.setBrief(json_3_createActivity.getBrief());
        activity.setUsertableByOwnerId(userForUse);
        activity.setIcon(json_3_createActivity.getIconString());

        //新建活动
        boolean addResult=actOperation.addOneAct(activity);
        if(addResult){
            //activitytable中添加成功
            System.out.println("activitytable中添加成功");

            //同时需要在actLinUser表中添加一条信息，表明创建者也在活动参与中。
            ActlinuserEntity actlinuserEntity=new ActlinuserEntity();
            actlinuserEntity.setUsertableByUserId(userForUse);
            List<ActivitytableEntity> allActivity=actOperation.findAllAct();
            actlinuserEntity.setActivitytableByActId(allActivity.get(allActivity.size()-1));
            boolean addResult2=actLinkUserOperation.addOneData(actlinuserEntity);
            if (addResult2){
                //actlinuser表中添加成功
                System.out.println("actlinuser中添加成功");
                json_3_createActivity.setResult(SportClientSymbol.SportActivity.CREATEACTIVITY_RESULT_SUCCESS);
            }else {
                //actlinuser中添加失败
                System.out.println("actlinuser中添加失败");
                json_3_createActivity.setResult(SportClientSymbol.SportActivity.CREATEACTIVITY_RESULT_FAIL_DATABASEWRONG);
            }


        }else {
            //activitytable中添加失败
            System.out.println("activitytable中添加失败");
            json_3_createActivity.setResult(SportClientSymbol.SportActivity.CREATEACTIVITY_RESULT_FAIL_DATABASEWRONG);
        }


        return json_3_createActivity;
    }




    //所有活动
    //活动--返回所有的活动
    public ArrayList<Json_3_activity_all> activity_all(Json_3_activity_all json_3_activity_all)
    {
        System.out.println("进入Logic-activity_all");

        ArrayList<Json_3_activity_all> my_list_all=new ArrayList<>();
        //找出所有活动
        List<ActivitytableEntity>  list_all=actOperation.findAllAct();
        //提取所需要的部分，放入返回的集合中
        for (int i = 0; i < list_all.size(); i++) {
            System.out.println("查找成功");

            Json_3_activity_all activity=new Json_3_activity_all();

            activity.setActivity_id(list_all.get(i).getId());
            activity.setIcon(list_all.get(i).getIcon());
            activity.setTitle(list_all.get(i).getTheam());
            activity.setBrief(list_all.get(i).getBrief());
            activity.setBeginTime(list_all.get(i).getBeginTime().toString());
            activity.setEndTime(list_all.get(i).getEndTime().toString());
            activity.setTotPeo(list_all.get(i).getTotPeo());
            activity.setResult(SportClientSymbol.SportActivity.ALLACTIVITIES_ALL_RESULT_SUCCESS);

            my_list_all.add(activity);
        }

        return my_list_all;
    }


    //活动--返回其中一个活动详情
    public Json_3_activity_single activity_single(Json_3_activity_single json_3_activity_single)
    {
        System.out.println("进入Logic-activity_single");

        //找出id对应的活动
        ActivitytableEntity activity=logicUtils.findActByActid(json_3_activity_single.getActivity_id());

        if (activity==null){
            System.out.println("查找失败-该活动ID没有记录");
            json_3_activity_single.setResult(SportClientSymbol.SportActivity.ALLACTIVITIES_SINGLE_RESULT_FAIL_NOTEXIST);
        }else {
            System.out.println("查找成功");
            //提取所需要的部分，放入返回的活动中
            json_3_activity_single.setActivity_id(activity.getId());
            json_3_activity_single.setIcon(activity.getIcon());
            json_3_activity_single.setTitle(activity.getTheam());
            json_3_activity_single.setBrief(activity.getBrief());
            json_3_activity_single.setBeginTime(activity.getBeginTime().toString());
            json_3_activity_single.setEndTime(activity.getEndTime().toString());
            json_3_activity_single.setLocation(activity.getLocation());
            json_3_activity_single.setState(activity.getStatus());
            json_3_activity_single.setTotPeo(activity.getTotPeo());
            json_3_activity_single.setResult(SportClientSymbol.SportActivity.ALLACTIVITIES_SINGLE_RESULT_SUCCESS);
        }

        return json_3_activity_single;
    }

    //活动-获取某个活动所有评论
    public ArrayList<Json_3_activity_comments_all> activity_comments_all(Json_3_activity_comments_all json_3_activity_comments_all){

        System.out.println("进入Logic-activity_comments_all");

        ArrayList<Json_3_activity_comments_all> my=new ArrayList<>();

        //找出id对应的活动
        ActivitytableEntity activity=logicUtils.findActByActid(json_3_activity_comments_all.getActivity_id());
        //根据活动Id找出该活动所有评论
        List<DiscusstableEntity> search=discussOperation.findActDisByActId(activity);
        //填充返回结果
        for (int i = 0; i < search.size(); i++) {

            System.out.println("查找成功");

            Json_3_activity_comments_all comment=new Json_3_activity_comments_all();

            comment.setActivity_id(json_3_activity_comments_all.getActivity_id());
            comment.setComment_id(search.get(i).getId());
            comment.setComment_otherpeo_id(search.get(i).getFollowId());
            //得到评论用户
            UsertableEntity user=search.get(i).getUsertableByUserId();
            comment.setComment_nickname(user.getName());
            comment.setComment_usericon(user.getHeadIcon());
            comment.setComment_content(search.get(i).getContent());
            comment.setResult(SportClientSymbol.SportActivity.ALLACTIVITIES_ALLCOMMENTS_RESULT_SUCCESS);

            my.add(comment);
        }

        return my;

    }


    //活动-在某个活动下进行评论
    public Json_3_activity_comments_create activity_comments_create(Json_3_activity_comments_create json_3_activity_comments_create){

        System.out.println("进入Logic-activity_comments_create");

        DiscusstableEntity discuss=new DiscusstableEntity();
        discuss.setContent(json_3_activity_comments_create.getComment_content());
        //判断是否评论活动
        if (json_3_activity_comments_create.getComment_otherpeo_id()==SportClientSymbol.SportActivity.ALLACTIVITIES_COMMENT_FOLLOWID_FOLLOWACTIVITY){
            //是评论活动的
            discuss.setActivitytableByActivityId(logicUtils.findActByActid(json_3_activity_comments_create.getActivity_id()));
            discuss.setFollowId(SportServerSymbol.discusstable.FOLLOWID_FOLLOWACTIVITY);
        }else {
            //评论他人的评论
            discuss.setActivitytableByActivityId(logicUtils.findActByActid(json_3_activity_comments_create.getActivity_id()));
            discuss.setFollowId(json_3_activity_comments_create.getComment_otherpeo_id());
        }
        discuss.setUsertableByUserId(logicUtils.findUser(json_3_activity_comments_create.getPhoneNumber()));

        //添加一条评论
        boolean addResult=discussOperation.addOneDis(discuss);
        if (addResult){
            System.out.println("添加成功");
            json_3_activity_comments_create.setResult(SportClientSymbol.SportActivity.ALLACTIVITIES_COMMENT_RESULT_SUCCESS);
        }else {
            System.out.println("添加失败");
            json_3_activity_comments_create.setResult(SportClientSymbol.SportActivity.ALLACTIVITIES_COMMENT_RESULT_FAIL_DATABASEWRONG);
        }

        return json_3_activity_comments_create;
    }

    //活动-申请参加某个活动
    public Json_3_activity_join activity_join(Json_3_activity_join json_3_activity_join){


        System.out.println("进入Logic-activity_join");

        //找到该用户
        UsertableEntity userForUse=logicUtils.findUser(json_3_activity_join.getPhoneNumber());
        //找到该活动
        ActivitytableEntity activityForUse=logicUtils.findActByActid(json_3_activity_join.getActivity_id());

        //先判断我已经参加了这个活动没有？
        List<ActivitytableEntity> myAllAct=actLinkUserOperation.findOneUserAllAct(userForUse);
        boolean inTheActivity=false;
        for (int i=0;i<myAllAct.size();i++){
            if (activityForUse.getId()==myAllAct.get(i).getId()){
                inTheActivity=true;
            }
        }
        if (inTheActivity){
            //我已经加入了过这个活动了
            System.out.println("我已经参加了这个活动了，无需再次申请");
            json_3_activity_join.setResult(SportClientSymbol.SportActivity.ALLACTIVITIES_JOIN_RESULT_FAIL_ALREADYIN);
        }else {
            //我没申请该活动，需要申请加入

            ParacttableEntity participate=new ParacttableEntity();
            //填充ParacttableEntity
            participate.setParTime(new Timestamp(System.currentTimeMillis()));
            participate.setStatus(SportServerSymbol.paracttable.STATUS_SUCCESS);
            participate.setActivitytableByActId(activityForUse);
            participate.setUsertableByUserId(userForUse);

            //在参加表中添加
            boolean addResult=parActOperation.addOnParAct(participate);
             if (addResult){
                //参加表中添加成功
                System.out.println("参加表中添加成功");

                //添加成功后还要在actlinuser表中修改相关记录
                 ActlinuserEntity actlinuserEntity=new ActlinuserEntity();
                 actlinuserEntity.setActivitytableByActId(activityForUse);
                 actlinuserEntity.setUsertableByUserId(userForUse);
                 boolean addResult2=actLinkUserOperation.addOneData(actlinuserEntity);
                 if (addResult2){
                     //actlinuser表中添加成功
                     System.out.println("actlinuser中添加成功");
                     json_3_activity_join.setResult(SportClientSymbol.SportActivity.ALLACTIVITIES_JOIN_RESULT_SUCCESS);
                     //同时还要修改活动表中某个活动的参与人数
                     //activityForUse.setTotPeo(actLinkUserOperation.findOneGroupAllUsers(activityForUse).size()+"");
                     activityForUse.setTotPeo(Integer.parseInt(activityForUse.getTotPeo())+1+"");
                     actOperation.updateOneActContent(activityForUse);
                 }else {
                     //actlinuser中添加失败
                     System.out.println("actlinuser中添加失败");
                     json_3_activity_join.setResult(SportClientSymbol.SportActivity.ALLACTIVITIES_JOIN_RESULT_FAIL_DATABASEWRONG);
                 }


            }else {
                //参加表中添加失败
                System.out.println("参加表中添加失败");
                json_3_activity_join.setResult(SportClientSymbol.SportActivity.ALLACTIVITIES_JOIN_RESULT_FAIL_DATABASEWRONG);
            }

        }

        return json_3_activity_join;
    }





    //我参与的
    //我参与的--返回我参与的所有的活动
    public ArrayList<Json_3_join_all> join_all(Json_3_join_all json_3_join_all)
    {
        System.out.println("进入Logic-join_all");

        ArrayList<Json_3_join_all> my_list_all=new ArrayList<>();
        //找出所有活动
        //ParacttableEntity userAttend=parActOperation.findByUserId(logicUtils.findUser(json_3_join_all.getPhoneNumber()));
        List<ActivitytableEntity>  list_all=new ArrayList<>();
       /* for (int j = 0; j < ; j++) {
            list_all.add();
        }*/
        //提取所需要的部分，放入返回的集合中
        for (int i = 0; i < list_all.size(); i++) {
            System.out.println("查找成功");

            Json_3_join_all activity=new Json_3_join_all();

            activity.setActivity_id(list_all.get(i).getId());
            activity.setIcon(list_all.get(i).getIcon());
            activity.setTitle(list_all.get(i).getTheam());
            activity.setBrief(list_all.get(i).getBrief());
            activity.setBeginTime(list_all.get(i).getBeginTime().toString());
            activity.setEndTime(list_all.get(i).getEndTime().toString());
            activity.setTotPeo(list_all.get(i).getTotPeo());
            activity.setResult("查找成功");

            my_list_all.add(activity);
        }

        return my_list_all;
    }


    //我参与的--返回我参与的其中一个活动详情
    public Json_3_join_single join_single(Json_3_join_single json_3_join_single)
    {
        System.out.println("进入Logic-join_single");

        //找出id对应的活动
        ActivitytableEntity activity=logicUtils.findActByActid(json_3_join_single.getActivity_id());

        if (activity==null){
            System.out.println("查找失败-该活动ID没有记录");
            json_3_join_single.setResult("查找失败-该活动ID没有记录");
        }else {
            System.out.println("查找成功");
            //提取所需要的部分，放入返回的活动中
            json_3_join_single.setActivity_id(activity.getId());
            json_3_join_single.setIcon(activity.getIcon());
            json_3_join_single.setTitle(activity.getTheam());
            json_3_join_single.setBrief(activity.getBrief());
            json_3_join_single.setBeginTime(activity.getBeginTime().toString());
            json_3_join_single.setEndTime(activity.getEndTime().toString());
            json_3_join_single.setLocation(activity.getLocation());
            json_3_join_single.setState(activity.getStatus());
            json_3_join_single.setTotPeo(activity.getTotPeo());
            json_3_join_single.setResult("查找成功");
        }

        return json_3_join_single;
    }

    //我参与的-获取我参与的某个活动所有评论
    public ArrayList<Json_3_join_comments_all> join_comments_all(Json_3_join_comments_all json_3_join_comments_all){

        System.out.println("进入Logic-join_comments_all");

        ArrayList<Json_3_join_comments_all> my=new ArrayList<>();

        //找出id对应的活动
        ActivitytableEntity activity=logicUtils.findActByActid(json_3_join_comments_all.getActivity_id());
        //根据活动Id找出该活动所有评论
        List<DiscusstableEntity> search=discussOperation.findActDisByActId(activity);
        //填充返回结果
        for (int i = 0; i < search.size(); i++) {

            System.out.println("查找成功");

            Json_3_join_comments_all comment=new Json_3_join_comments_all();

            comment.setActivity_id(json_3_join_comments_all.getActivity_id());
            comment.setComment_id(search.get(i).getId());
            //看是评论某一个活动的还是评论他人的评论
            if (search.get(i).getFollowId()!=null){
                //评论他人的评论
                //comment.setCommentActivity(false);
                comment.setComment_otherpeo_id(search.get(i).getFollowId());
            }else {
                //评论某个活动的
                //comment.setCommentActivity(true);
                //comment.setFollowId(search.get(i).getActivitytableByActivityId().getId());
                comment.setComment_otherpeo_id(-1);
            }
            //得到评论用户
            UsertableEntity user=search.get(i).getUsertableByUserId();
            //comment.setComment_nickname(user.get);
            comment.setComment_usericon(user.getHeadIcon());
            comment.setComment_content(search.get(i).getContent());
            comment.setResult("查找成功");

            my.add(comment);
        }

        return my;

    }


    //我参与的-在我参与的某个活动下进行评论
    public Json_3_join_comments_create join_comments_create(Json_3_join_comments_create json_3_join_comments_create){

        System.out.println("进入Logic-join_comments_create");

        DiscusstableEntity discuss=new DiscusstableEntity();
        discuss.setContent(json_3_join_comments_create.getComment_content());
        //判断是否评论活动
        if (json_3_join_comments_create.getComment_otherpeo_id()<0){
            //是评论活动的
            discuss.setActivitytableByActivityId(logicUtils.findActByActid(json_3_join_comments_create.getActivity_id()));
        }else {
            //评论他人的评论
            discuss.setActivitytableByActivityId(logicUtils.findActByActid(json_3_join_comments_create.getActivity_id()));
            discuss.setFollowId(json_3_join_comments_create.getComment_otherpeo_id());
        }
        discuss.setUsertableByUserId(logicUtils.findUser(json_3_join_comments_create.getPhoneNumber()));

        //添加一条评论
        boolean addResult=discussOperation.addOneDis(discuss);
        if (addResult){
            System.out.println("添加成功");
            json_3_join_comments_create.setResult("添加成功");
        }else {
            System.out.println("添加失败");
            json_3_join_comments_create.setResult("添加失败");
        }

        return json_3_join_comments_create;
    }

    //我参与的-退出我参与的某个活动
    public Json_3_join_signout join_signout(Json_3_join_signout json_3_join_signout){


        System.out.println("进入Logic-join_signout");

        ParacttableEntity participate=new ParacttableEntity();
        //填充ParacttableEntity
        participate.setParTime(new Timestamp(System.currentTimeMillis()));
        participate.setStatus("申请退出");
        ActivitytableEntity activityForUse=logicUtils.findActByActid(json_3_join_signout.getActivity_id());
        participate.setActivitytableByActId(activityForUse);
        UsertableEntity userForUse=logicUtils.findUser(json_3_join_signout.getPhoneNumber());
        participate.setUsertableByUserId(userForUse);

        //添加
        boolean addResult=parActOperation.addOnParAct(participate);
        if (addResult){

            //添加退出记录后还要在表中活动减去参与人员与参与人数
            if (activityForUse.getOtherPeoId()==null) {
                //添加退出记录
                System.out.println("退出活动失败");
                json_3_join_signout.setResult("退出活动失败，活动人员ID为空");
            }else {
                String attendPeopleId=activityForUse.getOtherPeoId();
                String[] attendPeopleIdArray=attendPeopleId.split(" ");
                String attendResult="";
                for (int i = 0; i < attendPeopleIdArray.length; i++) {
                    if ((Integer.parseInt(attendPeopleIdArray[i]))!=(userForUse.getId())){
                        if (i==0){
                            attendResult=attendPeopleIdArray[i];
                        }else {
                            attendResult=attendResult+" "+attendPeopleIdArray[i];
                        }
                    }
                }

                activityForUse.setOtherPeoId(attendResult);
            }

            if (activityForUse.getTotPeo()==null) {
                //添加退出记录
                System.out.println("退出活动失败");
                json_3_join_signout.setResult("退出活动失败，活动人员总数为空");
            }else if (Integer.parseInt(activityForUse.getTotPeo())==0){
                //添加退出记录
                System.out.println("退出活动失败");
                json_3_join_signout.setResult("退出活动失败，活动人员总数为0");
            } else {
                activityForUse.setTotPeo((Integer.parseInt(activityForUse.getTotPeo())-1)+"");

            }

            System.out.println("退出活动成功");
            json_3_join_signout.setResult("退出活动成功");


        }else {
            //添加失败
            System.out.println("退出活动失败");
            json_3_join_signout.setResult("退出活动失败");
        }

        return json_3_join_signout;
    }






    //我发布的MYRELEASE
    //我发布的--返回我发布的所有的活动
    public ArrayList<Json_3_release_all> release_all(Json_3_release_all json_3_release_all)
    {
        System.out.println("进入Logic-release_all");

        ArrayList<Json_3_release_all> my_list_all=new ArrayList<>();
        //找出所有活动
        List<ActivitytableEntity>  list_all=actOperation.findByUserId(logicUtils.findUser(json_3_release_all.getPhoneNumber()));
        //提取所需要的部分，放入返回的集合中
        for (int i = 0; i < list_all.size(); i++) {
            System.out.println("查找成功");

            Json_3_release_all activity=new Json_3_release_all();

            activity.setActivity_id(list_all.get(i).getId());
            activity.setIcon(list_all.get(i).getIcon());
            activity.setTitle(list_all.get(i).getTheam());
            activity.setBrief(list_all.get(i).getBrief());
            activity.setBeginTime(list_all.get(i).getBeginTime().toString());
            activity.setEndTime(list_all.get(i).getEndTime().toString());
            activity.setTotPeo(list_all.get(i).getTotPeo());
            activity.setResult(SportClientSymbol.SportActivity.MYRELEASE_ALL_RESULT_SUCCESS);

            my_list_all.add(activity);
        }

        return my_list_all;
    }


    //我发布的--返回我发布的其中一个活动详情
    public Json_3_release_single release_single(Json_3_release_single json_3_release_single)
    {
        System.out.println("进入Logic-join_single");

        //找出id对应的活动
        ActivitytableEntity activity=logicUtils.findActByActid(json_3_release_single.getActivity_id());

        if (activity==null){
            System.out.println("查找失败-该活动ID没有记录");
            json_3_release_single.setResult("查找失败-该活动ID没有记录");
        }else {
            System.out.println("查找成功");
            //提取所需要的部分，放入返回的活动中
            json_3_release_single.setActivity_id(activity.getId());
            json_3_release_single.setIcon(activity.getIcon());
            json_3_release_single.setTitle(activity.getTheam());
            json_3_release_single.setBrief(activity.getBrief());
            json_3_release_single.setBeginTime(activity.getBeginTime().toString());
            json_3_release_single.setEndTime(activity.getEndTime().toString());
            json_3_release_single.setLocation(activity.getLocation());
            json_3_release_single.setState(activity.getStatus());
            json_3_release_single.setTotPeo(activity.getTotPeo());
            json_3_release_single.setResult(SportClientSymbol.SportActivity.MYRELEASE_SINGLE_RESULT_SUCCESS);
        }

        return json_3_release_single;
    }

    //我参与的-获取我发布的某个活动所有评论
    public ArrayList<Json_3_release_comments_all> release_comments_all(Json_3_release_comments_all json_3_release_comments_all){

        System.out.println("进入Logic-release_comments_all");

        ArrayList<Json_3_release_comments_all> my=new ArrayList<>();

        //找出id对应的活动
        ActivitytableEntity activity=logicUtils.findActByActid(json_3_release_comments_all.getActivity_id());
        //根据活动Id找出该活动所有评论
        List<DiscusstableEntity> search=discussOperation.findActDisByActId(activity);
        //填充返回结果
        for (int i = 0; i < search.size(); i++) {

            System.out.println("查找成功");

            Json_3_release_comments_all comment=new Json_3_release_comments_all();

            comment.setActivity_id(json_3_release_comments_all.getActivity_id());
            comment.setComment_id(search.get(i).getId());
            comment.setComment_otherpeo_id(search.get(i).getFollowId());
            //得到评论用户
            UsertableEntity user=search.get(i).getUsertableByUserId();
            comment.setComment_nickname(user.getName());
            comment.setComment_usericon(user.getHeadIcon());
            comment.setComment_content(search.get(i).getContent());
            comment.setResult(SportClientSymbol.SportActivity.MYRELEASE_ALLCOMMENTS_RESULT_SUCCESS);

            my.add(comment);
        }

        return my;

    }


    //我发布的-在我发布的某个活动下进行评论
    public Json_3_release_comments_create release_comments_create(Json_3_release_comments_create json_3_release_comments_create){

        System.out.println("进入Logic-release_comments_create");

        DiscusstableEntity discuss=new DiscusstableEntity();
        discuss.setContent(json_3_release_comments_create.getComment_content());
        //判断是否评论活动
        if (json_3_release_comments_create.getComment_otherpeo_id()==SportClientSymbol.SportActivity.MYRELEASE_COMMENT_FOLLOWID_FOLLOWACTIVITY){
            //是评论活动的
            discuss.setActivitytableByActivityId(logicUtils.findActByActid(json_3_release_comments_create.getActivity_id()));
            discuss.setFollowId(SportServerSymbol.discusstable.FOLLOWID_FOLLOWACTIVITY);
        }else {
            //评论他人的评论
            discuss.setActivitytableByActivityId(logicUtils.findActByActid(json_3_release_comments_create.getActivity_id()));
            discuss.setFollowId(json_3_release_comments_create.getComment_otherpeo_id());
        }
        discuss.setUsertableByUserId(logicUtils.findUser(json_3_release_comments_create.getPhoneNumber()));

        //添加一条评论
        boolean addResult=discussOperation.addOneDis(discuss);
        if (addResult){
            System.out.println("添加成功");
            json_3_release_comments_create.setResult(SportClientSymbol.SportActivity.MYRELEASE_COMMENT_RESULT_SUCCESS);
        }else {
            System.out.println("添加失败");
            json_3_release_comments_create.setResult(SportClientSymbol.SportActivity.MYRELEASE_COMMENT_RESULT_FAIL_DATABASEWRONG);
        }

        return json_3_release_comments_create;
    }

    //我发布的-取消我发布的某个活动
    public Json_3_release_cancel release_cancel(Json_3_release_cancel json_3_release_cancel) {


        System.out.println("进入Logic-release_cancel");

        //找到该用户
        UsertableEntity userForUse = logicUtils.findUser(json_3_release_cancel.getPhoneNumber());
        //找到该活动
        ActivitytableEntity activityForUse = logicUtils.findActByActid(json_3_release_cancel.getActivity_id());

        //先判断这个活动是不是我管理的
        List<ActivitytableEntity> myAllManageAct = actOperation.findByUserId(userForUse);
        boolean isTheActiIMan = false;
        for (int i = 0; i < myAllManageAct.size(); i++) {
            if (myAllManageAct.get(i).getId() == json_3_release_cancel.getActivity_id()) {
                isTheActiIMan = true;
            }
        }
        if (isTheActiIMan) {
            //我是这个活动的管理者，我有权限管理这个活动
            System.out.println("我是这个活动的管理者，我有权限管理这个活动");
            //修改Activitytable表状态
            ActivitytableEntity activity = actOperation.findByActId(logicUtils.findActByActid(json_3_release_cancel.getActivity_id()));
            activity.setStatus(SportServerSymbol.activitytable.STATUS_CANCEL);
            boolean updateResult = actOperation.updateOneActContent(activity);
            if (updateResult) {
                System.out.println("取消活动成功");
                json_3_release_cancel.setResult(SportClientSymbol.SportActivity.MYRELEASE_CANCEL_RESULT_SUCCESS);
            }
            else {
                System.out.println("取消活动失败");
                json_3_release_cancel.setResult(SportClientSymbol.SportActivity.MYRELEASE_CANCEL_RESULT_FAIL_DATABASEWRONG);
            }
        } else {
            //我不是这个活动的管理者，我没有权限管理这个活动
            System.out.println("我不是这个活动的管理者，我没有权限管理这个活动");
            json_3_release_cancel.setResult(SportClientSymbol.SportActivity.MYRELEASE_CANCEL_RESULT_FAIL_NOAUTHORITY);
        }

        return json_3_release_cancel;
    }


}
